package initializers;

import java.awt.Panel;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JTabbedPane;

import mainPanels.ConversionPanel;
import mainPanels.FixPanel;
import configuration.WindowSettings;

public class TabPaneInitializer implements Initializer<JTabbedPane>
{
	private Map<String, Panel> mainPanels;
	private JTabbedPane tabbedPane;
	
	public TabPaneInitializer(JTabbedPane tabbedPane) 
	{
		this.tabbedPane = tabbedPane;
	}

	private void initializeMainPanelsMap()
	{
		if(mainPanels == null)
		{
			mainPanels = new LinkedHashMap<>();
			mainPanels.put(WindowSettings.COVERSION_TAB_NAME, new ConversionPanel());
			mainPanels.put(WindowSettings.FIX_TAB_NAME, new FixPanel());
		}
	}
	
	@Override
	public JTabbedPane initialize() 
	{
		initializeMainPanelsMap();
		return initializeTabComponent(tabbedPane);
	}
	
	private JTabbedPane initializeTabComponent(JTabbedPane tabbedPane)
	{	
		if(tabbedPane != null)
		{
			tabbedPane = new JTabbedPane();
			tabbedPane.setSize(500, 500);
			
			for(Entry<String, Panel> entry : mainPanels.entrySet())
			{
				tabbedPane.addTab(entry.getKey(), entry.getValue());
			}
			
			return tabbedPane;
		}
		
		return null;
	}
}

